/****************************************************************************
 * Copyright (c) 2008, 2009 Andreas Unger and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Andreas Unger - initial API and implementation 
 ****************************************************************************/

package org.eclipselabs.damos.diagram.ui.properties;

import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.eclipselabs.damos.diagram.core.internal.commands.SetArgumentValueCommand;
import org.eclipselabs.damos.diagram.ui.internal.util.PropertySectionUtil;
import org.eclipselabs.damos.dml.Argument;
import org.eclipselabs.damos.dml.DMLFactory;
import org.eclipselabs.damos.dml.ExpressionSpecification;

/**
 * @author Andreas Unger
 *
 */
public class BooleanParameterCompositeDelegate extends CheckboxPropertyCompositeDelegate implements IParameterCompositeDelegate {

	private Argument argument;
	
	public BooleanParameterCompositeDelegate(TabbedPropertySheetWidgetFactory widgetFactory, Argument argument) {
		super(widgetFactory);
		this.argument = argument;
	}

	public void refreshParameter() {
		getCheckboxWidget().setSelection(Boolean.parseBoolean(argument.getValue().stringValue()));
	}

	/* (non-Javadoc)
	 * @see org.eclipselabs.damos.diagram.ui.properties.AbstractPropertySectionDelegate#getLabelText()
	 */
	protected String getLabelText() {
		return PropertySectionUtil.formatName(argument.getParameter().getName());
	}
	
	/* (non-Javadoc)
	 * @see org.eclipselabs.damos.diagram.ui.properties.CheckboxPropertySectionDelegate#updatePropertyValue()
	 */
	protected void updatePropertyValue() {
		ExpressionSpecification expressionSpec = DMLFactory.eINSTANCE.createExpressionSpecification();
		expressionSpec.setExpression(Boolean.toString(getCheckboxWidget().getSelection()));
		executeOperation(new SetArgumentValueCommand(argument, expressionSpec));
	}
	
}
